<template>
  <div>
    <home-header></home-header>
    <home-swiper :swiperList="swiperList"></home-swiper>
    <home-icons :iconList="iconList"></home-icons>
    <home-list :recommendList="recommendList" ></home-list>
    <home-weekend :weekendList="weekendList"></home-weekend>
    <action-list></action-list>
  </div>
</template>

<script type="text/ecmascript-6">
import HomeHeader from './component/header'
import HomeSwiper from './component/swiper'
import HomeIcons from './component/iconMenu'
import HomeList from './component/list'
import HomeWeekend from './component/weekend'
import ActionList from './component/actionList'
import axios from 'axios'
import { mapState } from 'vuex'

export default {
  name: 'Home',
  components: {
    HomeHeader,
    HomeSwiper,
    HomeIcons,
    HomeList,
    HomeWeekend,
    ActionList
  },
  data () {
    return {
      swiperList: [],
      iconList: [],
      recommendList: [],
      weekendList: []
    }
  },
  methods: {
    getHomeInfo () {
      var _this = this
      axios.get('/api/index.json?city=' + this.city).then(function (res) {
        res = res.data
        if (res.ret && res.data) {
          const data = res.data
          _this.swiperList = data.swiperList
          _this.iconList = data.iconList
          _this.recommendList = data.recommendList
          _this.weekendList = data.weekendList
        }
      })
    }
  },
  computed: {
    ...mapState({
      city: 'city'
    })
  },
  mounted () {
    this.getHomeInfo()
  },
  activated () {
    if (this.lastCity !== this.city) {
      this.lastCity = this.city
      this.getHomeInfo()
    }
  }
}
</script>

<style lang="scss" scoped>

</style>
